package com.lefevre.cms.web.action.message;

import com.lefevre.cms.bean.message.SubscriptionSystemNotify;
import com.lefevre.cms.utils.Verification;
import org.springframework.stereotype.Component;

/**
 * 订阅系统通知管理
 */
@Component("subscriptionSystemNotifyManage")
public class SubscriptionSystemNotifyManage {

    /**
     * 取得订阅系统通知Id的用户Id(后N位)
     *
     * @param subscriptionSystemNotify 订阅系统通知Id
     * @return
     */
    public int getSubscriptionSystemNotifyId(String subscriptionSystemNotifyId) {
        String after_userId = subscriptionSystemNotifyId.substring(subscriptionSystemNotifyId.length() - 4, subscriptionSystemNotifyId.length());
        return Integer.parseInt(after_userId);
    }

    /**
     * 生成订阅系统通知Id
     * 订阅系统通知Id由18位系统通知Id + 18位用户Id组成
     *
     * @param systemNotifyId 系统通知Id
     * @param userId         用户Id
     * @return
     */
    public String createSubscriptionSystemNotifyId(Long systemNotifyId, Long userId) {
        if (systemNotifyId < 999999999999999999L && userId < 999999999999999999L) {
            // 0 代表前面补充0
            // 4 代表长度为4
            // d 代表参数为正数型
            String before = String.format("%018d", systemNotifyId);//补0
            String after = String.format("%018d", userId);//补0
            return before + after;
        }
        return null;
    }

    /**
     * 校验订阅系统通知Id
     * 订阅系统通知Id要先判断是否36位并且最后4位是数字
     *
     * @param subscriptionSystemNotifyId 私信Id
     * @return
     */
    public boolean verificationSubscriptionSystemNotifyId(String subscriptionSystemNotifyId) {
        if (subscriptionSystemNotifyId != null && !"".equals(subscriptionSystemNotifyId.trim())) {
            if (subscriptionSystemNotifyId.length() == 36) {
                String after_userId = subscriptionSystemNotifyId.substring(subscriptionSystemNotifyId.length() - 4, subscriptionSystemNotifyId.length());
                boolean verification = Verification.isPositiveIntegerZero(after_userId);//数字
                if (verification) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 生成订阅系统通知对象
     *
     * @return
     */
    public Object createSubscriptionSystemNotifyObject(SubscriptionSystemNotify subscriptionSystemNotify) {
        return subscriptionSystemNotify;
    }


}
